<template>
	<view class="minishop-goods-list" :class="config.style">
		<view class="header">
			<text class="title">{{params.title}}</text>
			<text class="more" @click="goToMoreLink()">查看更多</text>
		</view>
		<view class="list" :class="params.rank == 1 ? 'rank1':'rank0'">
			<view :class="params.style == 1 ? 'style1':'style0'">
				<view class="item" v-for="(item,index) in params.list" :key="index" @click="goToDetailLink(item.id)">
					<view class="content">
						<view class="cover">
							<image mode="widthFix" :src="item.cover_400" @error="imageError" class="image"></image>
						</view>
						<view class="info">
							<view class="title text-ellipsis-2">{{item.title}}</view>
							<view class="description text-ellipsis" v-if="params.style != 1 && params.rank == 1">{{item.description}}</view>
							<view class="price">￥ {{handlePrice(item.price,0)}}.<text class="pointback">{{handlePrice(item.price,1)}}</text></view>
							<view class="exp-info">
								<view class="item view">
									<uni-icons type="eye" size="10" color="#999999"></uni-icons> 
									<text class="num">{{item.handling_view}}</text>
								</view>
								<view class="item sales">
									<uni-icons type="cart-filled" size="10" color="#999999"></uni-icons> 
									<text class="num">{{item.handling_sales}}</text>
								</view>
								<view class="item favorites">
									<uni-icons type="star" size="10" color="#999999"></uni-icons> 
									<text class="num">{{item.handling_sales}}</text>
								</view>
							</view>
							
						</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import siteInfo from '../../../siteinfo.js'
	export default {
		name: 'MinishopGoodsList',
		props: {
			title: {
				type: String,
				default: '云小店商品列表'
			},
			type: {
				type: String,
				default: 'minishop_goods_list',
			},
			params: {
				type: Object,
				default: {},
			},
			config: {
				type: Object,
				default: {},
			},
		},
		data() {
			return {
				
			}
		},
		created() {
			//console.log(JSON.stringify(this.params))
			this.getLinkMoreParams();
			//console.log(this.params);
		},
		
		methods: {
			
			/**
			 * 获取链接参数
			 */
			getLinkMoreParams: function(){
				let linkMoreParams = {
					category_id : this.params.category_id,
					order_field : this.params.order_field,
					order_type: this.params.order_type,
				}
				//console.log(linkParams);
				this.linkMoreParams = linkMoreParams
			},
			
			/**
			 * 路由至商品列表页面
			 */
			goToMoreLink: function(){
				let params = this.linkMoreParams
				let urlParams = this.util.urlEncode(params)
				//console.log(urlParams)
				let url = '../../pages/goods/lists?' + urlParams
				//指定跳转地址
				uni.navigateTo({
				    url: url
				});
			},
			
			/**
			 * 跳转至商品详情页
			 * @param {Object} id
			 */
			goToDetailLink: function(id){
				let urlParams = 'id='+id
				let url = '../../pages/goods/detail?' + urlParams
				console.log(url)
				//指定跳转地址
				uni.navigateTo({
				    url: url
				});
				
			},
			
			handlePrice(price,index){
				return price.split('.')[index];
			}
		},
        
	}
</script>

<style lang="scss">
	.minishop-goods-list {
		.header {
			display: flex;
			justify-content: space-between;
			padding: 20rpx;
			
			.title {
				flex: 1;
				font-size: 36rpx;
				font-weight: 700;
				line-height: 56rpx;
				color: #353637;
				font-family: 'PingFangSC-Medium, PingFang SC';
			}
			.more {
				color: #999;
				font-size: 26rpx;
				line-height: 56rpx;
			}
		}
		/*横排*/
		.list.rank0 {
			
			/*小图*/
			.style0{
				display: flex;
				flex-wrap: wrap;
				padding: 0 10rpx;
				.item {
					box-sizing:border-box;
					width: 50%;
					.content {
						margin: 0 10rpx;
						padding-bottom: 20rpx;
						background-color: #fff;
						border-radius: 14rpx;
						.cover {
							border-radius: 14rpx;
							overflow: hidden;
							.image {
								width: 100%;
								display: block;
							}
						}
						.info {
							.title {
								margin-top: 16rpx;
								font-size: 24rpx;
								color: #2d2e2f;
								height: 72rpx;
								line-height: 36rpx;
							}
							.description {
								color: #999;
								font-size: 24rpx;
							}
							.price {
								margin-top: 10rpx;
								font-size: 30rpx;
								font-weight: 600;
								// font-family: "PingFangSC-Regular, PingFang SC";
								line-height: 36rpx;
								.pointback{
									font-size: 12px;
								}
							}
							.exp-info {
								margin-top: 10rpx;
								color: #999;
								font-size: 24rpx;
								.item {
									display: inline;
									.num {
										margin: 0 10rpx;
									}
								}
							}
						}
					}
				}
			}
		}
		/*竖排*/
		.list.rank1 {
			/*小图*/
			.style0{
				display: flex;
				flex-wrap: wrap;
				.item {
					width: 100%;
					.content {
						padding: 10rpx;
						display: flex;
						flex-wrap: wrap;
						.cover {
							width: 280rpx;
							border-radius: 10rpx;
							overflow: hidden;
							.image {
								width: 100%;
								display: block;
							}
						}
						.info {
							padding-left: 20rpx;
							flex: 1;
							.title {
								font-size: 28rpx;
								color: #000;
								font-weight: 600;
								height: 72rpx;
								line-height: 36rpx;
							}
							.description {
								color: #999;
								font-size: 24rpx;
							}
							.price {
								margin-top: 10rpx;
								font-size: 26rpx;
							}
							.exp-info {
								margin-top: 10rpx;
								color: #999;
								font-size: 24rpx;
								.item {
									display: inline;
									.num {
										margin: 0 10rpx;
									}
								}
							}
						}
					}
				}
			}
		}
	}
	
	/*页面风格设计*/
	.Blue {
		.price {
			color: $Blue;
		}
	}
	.Green {
		.price {
			color: $Green;
		}
	}
	.LightRed {
		.price {
			color: $LightRed;
		}
	}
	.Orange {
		.price {
			color: $Orange;
		}
	}
	.LightPink {
		.price {
			color: $LightPink;
		}
	}
	.Magenta {
		.price {
			color: $Magenta;
		}
	}
</style>
